home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / games / tmloto13.zip / TIMELOTO.MEX < prev    next >
Text File  |  1996-10-30  |  16KB  |  460 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Normal rules apply,this is my copyrighted program etc                   //
  3. // If you use and like the program please either netmail or email me at    //
  4. // the address' below.If you like to send some money,then let me know and  //
  5. // I'll give you my home address :)                                        //
  6. //                                                                         //
  7. // You may alter this program for YOUR OWN USE ONLY,you cannot alter it    //
  8. // and send it out in a modified form.                                     //
  9. // I'd welcome comments,bug reports,ideas or code to be added              //
  10. // You may reach me at : 2:253/35@fidonet                                  //
  11. //                       240:360/45@mercury                                //
  12. //                       81:444/25@os2net                                  //
  13. //                       mark.taylor@zetnet.co.uk (Quickest)               //
  14. //                       mark@trythat.coracle.com                          //
  15. /////////////////////////////////////////////////////////////////////////////
  16.  
  17.  
  18. #include <max.mh>
  19. #include <rand.mh>
  20.  
  21. #define VERSION    " V1.3\n"  // Version number
  22.  
  23. #define MAX_LINES 10          // Maximum number of lines,use the users screen length
  24. #define RANDOM    49          // Maximum value of number to pick
  25. #define BALLS      6          // Number of random numbers to pick per line
  26. #define TRY       50          // Number of random numbers before one is picked
  27. #define BET        2          // Number of minutes to gamble on each line
  28. #define MATCHED_1  1          // Number of minutes given for 1 number matched per line
  29. #define MATCHED_2  2          // Number of minutes given for 2 numbers matched per line
  30. #define MATCHED_3  5          // Number of minutes given for 3 numbers matched per line
  31. #define MATCHED_4 10          // Number of minutes given for 4 numbers matched per line
  32. #define MATCHED_5 15          // Number of minutes given for 5 numbers matched per line
  33. #define MATCHED_6 25          // Number of minutes given for 6 numbers matched per line
  34. #define MAX_TIME 120          // Maxium of time allowed for each user to be added
  35.  
  36. int:    minutes_won ,    // total minutes won,if any :)
  37.         winning_lines ,  // How many winning lines
  38.         number_of_bets ; // How many bets (lines)
  39. long: start_mins ;       // minutes left at start
  40. string: blanks ;         // Blank line
  41.  
  42. array [1..BALLS] of int: computer_balls ; // Array for chosen balls
  43. array [1..BALLS] of int: user_balls ;  // Array for user chosen lottery balls
  44.  
  45. // Prototypes
  46. string centre(string: s1) ;
  47. void cls() ;
  48. void print_title() ;
  49. void pick_numbers(array [1..BALLS] of int: balls) ;
  50. int getrandom() ;
  51. void sort_numbers(array[1..BALLS] of int: balls) ;
  52. void get_user_numbers() ;
  53. void get_number_of_trys() ;
  54. void print_line(array[1..BALLS] of int: balls,int: x) ;
  55. int check_for_match(int: ball_to_check) ;
  56. void help() ;
  57. void print_stats() ;
  58. int main() ;
  59.  
  60.  
  61.  
  62. // Centre Output
  63. string centre(string: s1)
  64. {
  65.   string: s2;
  66.   int: i1;
  67.   s2:="\r";
  68.   for(i1:=1; i1<=(((term_width()-2)-strlen(s1))/2); i1:=i1+1)
  69.      { s2:=s2+" "; }
  70.   s2:=s2+s1;
  71.   return s2;
  72. }
  73.  
  74. // Clear Screen
  75. void cls()
  76. {
  77.   print("\x0c");
  78. }
  79.  
  80. // Just print out title and advert etc..
  81. void print_title()
  82. {
  83.   cls() ;
  84.   print(COL_LCYAN) ;
  85.   print(centre("Lottery Time Gamble"+VERSION)) ;
  86.   print(centre("Written By Mark Taylor (c)\n")) ;
  87.   print(centre("TryThat SoftWare  1996\n")) ;
  88.   print(COL_WHITE"\n") ;
  89. }
  90.  
  91. // computer picked numbers
  92. void pick_numbers(array [1..BALLS] of int: balls)
  93. {
  94. int: i,x,test,number ;
  95.  
  96.   print(AVATAR_GOTO,(char)10,(char)40,COL_WHITE "                   ") ;
  97.   print(AVATAR_GOTO,(char)10,(char)40,COL_WHITE "Picking Numbers ") ;
  98.  
  99.   for(i := 1 ; i <= BALLS ; i := i+1)
  100.      {
  101.      balls[i] := 50 ;  // Set ball to a number,that is false
  102.      test := FALSE ;
  103.      while(test = FALSE)
  104.           {
  105.           test := TRUE ;
  106.           number := getrandom() ; // Get a random ball
  107.           // Make sure no dupes
  108.           for(x := 1 ; x < BALLS+1 ; x := x+1)
  109.              if(balls[x] = number)
  110.                test := FALSE ;
  111.           }
  112.      balls[i] := number ;
  113.      }
  114.   sort_numbers(balls) ;
  115. }
  116.  
  117. // get a random number and print spinning bar
  118. int getrandom()
  119. {
  120. int: number,z ;
  121.  
  122.   for(z := 0 ; z < TRY ; z := z+1)
  123.      {
  124.      number := (rand()%RANDOM)+1 ; // Get a random number
  125.      if(z/4 = 0)
  126.        print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE "\\") ;
  127.      if(z/8 = 0)
  128.        print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE "-") ;
  129.      if(z/12 = 0)
  130.        print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE "/") ;
  131.      if(z/16 = 0)
  132.        print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE "|") ;
  133.      }
  134.   print(AVATAR_GOTO,(char)10,(char)60,COL_WHITE " ") ;
  135.  
  136. return number ;
  137. }
  138.  
  139. // Put balls into order
  140. void sort_numbers(array[1..BALLS] of int: balls)
  141. {
  142. // There may be a faster way to sort,but then again there are'nt many numbers
  143.  
  144. int: swtch,x,temp ;
  145.  
  146.    swtch := TRUE ;
  147.    while(swtch = TRUE)
  148.         {
  149.         swtch := FALSE ;
  150.         for(x := 1; x < BALLS ; x := x+1)
  151.            if(balls[x] >balls[x+1])
  152.              {
  153.              temp := balls[x] ;
  154.              balls[x] := balls[x+1] ;
  155.              balls[x+1] := temp ;
  156.              swtch := TRUE ;
  157.              }
  158.         }
  159. }
  160.  
  161. // get user numbers
  162. void get_user_numbers()
  163. {
  164. int:    number,swtch,x,i;
  165. string: get_number,prompt;
  166.  
  167.   print(AVATAR_GOTO,(char)10,(char)1,blanks) ;
  168.   // print line ready to display user numbers
  169.   print(AVATAR_GOTO,(char)10,(char)1,"Your Numbers - ") ;
  170.  
  171.  
  172.   for(i := 1 ; i < BALLS+1 ; i := i+1)
  173.       {
  174.       prompt := "Please enter a number between 1 and "+itostr(RANDOM)+",then press return ";
  175.       swtch := TRUE ;
  176.       user_balls[i] := 50 ; // set a dummy number
  177.       while(swtch = TRUE)
  178.            {
  179.            while(swtch = TRUE)
  180.                 {
  181.                 // Get a number between 1 & RANDOM (49)
  182.                 print(AVATAR_GOTO,(char)5,(char)1,blanks) ; // Print a line of blanks
  183.                 print(AVATAR_GOTO,(char)5,(char)1 ) ;
  184.                 input_str(get_number, INPUT_WORD, 0, 2,prompt);
  185.                 number := strtoi(get_number) ;
  186.                 if(number < 1 OR number > RANDOM)
  187.                    prompt := "You must enter a number between 1 and "+itostr(RANDOM)+" " ;
  188.                 else
  189.                    swtch := FALSE ;
  190.                 }
  191.  
  192.            // Make sure no dupes
  193.            for(x := 1 ; x < BALLS+1 ; x := x+1)
  194.               if(user_balls[x] = number)
  195.                 {
  196.                 swtch := TRUE ;
  197.                 prompt := "Please pick a differnt a number " ;
  198.                 }
  199.  
  200.            // this is a good number,so use it
  201.            if(swtch = FALSE)
  202.              {
  203.              user_balls[i] := number ;
  204.              print(AVATAR_GOTO,(char)10,(char)(15+(i*3)),COL_YELLOW,number,COL_WHITE) ;
  205.              }
  206.            }
  207.       }
  208.  
  209.   sort_numbers(user_balls) ;   // put the balls in order
  210. }
  211.  
  212. // get number of lines to bet on
  213. void get_number_of_trys()
  214. {
  215. int:    swtch ;
  216. string: get_number,prompt ;
  217. long: number ;
  218.  
  219.   number := timeleft() / BET ;  // Get users time left,and see how many bets
  220.   if(number > MAX_LINES)        // available.
  221.      number := MAX_LINES ;      // If more than max limit,set it to max limit
  222.  
  223.   prompt := "You have "+ltostr(timeleft())+" minutes to play with.\n"+
  224.             "Enter how many bets you'd like,upto a maximum of "+
  225.             ltostr(number)+",\nand remember each bet is "+itostr(BET)+
  226.             " Minutes taken off of your time? ";
  227.  
  228.   swtch := TRUE ;
  229.   while(swtch = TRUE)
  230.        {
  231.        print(AVATAR_GOTO,(char)5,(char)1,blanks) ; // Print a blank line
  232.        print(AVATAR_GOTO,(char)6,(char)1,blanks) ; // Print a blank line
  233.        print(AVATAR_GOTO,(char)7,(char)1,blanks) ; // Print a blank line
  234.        print(AVATAR_GOTO,(char)5,(char)1 ) ;       // set ready for printing
  235.        input_str(get_number, INPUT_WORD, 0, 2,prompt);
  236.        number_of_bets := strtoi(get_number) ;   // convert string to int
  237.        if(number_of_bets < 1 OR number_of_bets > number)
  238.           prompt := "You must enter a number between 1 and "+ltostr(number)+" ? " ;
  239.        else
  240.           swtch := FALSE ;
  241.        }
  242.  
  243.   timeadjustsoft(-(number_of_bets * BET * 60) ) ; // take off bet from users time
  244.   print(AVATAR_GOTO,(char)5,(char)1,blanks) ; // Print a blank line
  245.   print(AVATAR_GOTO,(char)6,(char)1,blanks) ;
  246.   print(AVATAR_GOTO,(char)7,(char)1,blanks) ;
  247. //  print(AVATAR_GOTO,(char)6,(char)1 ) ;
  248. //  print("You have ",timeleft()," minutes left,after your bet of ",number_of_bets * BET," minutes.\n") ;
  249.   log("TBet "+itostr(number_of_bets * BET)+" minutes" ); // Log the bet to logfile
  250.  
  251. // return number ;
  252. }
  253.  
  254. // print out each computer line,then check for any winning numbers
  255. void print_line(array[1..BALLS] of int: balls,int: x)
  256. {
  257. int: y,matches ;
  258.  
  259.   matches := 0 ;
  260.   // Print out results,pad with spaces to make neat
  261.   print(AVATAR_GOTO,(char)(11+x),(char)1,
  262.         COL_LRED,"Line ",strpadleft(itostr(x),2,' ')," : ",COL_WHITE) ;
  263.  
  264.   for(y := 1 ; y < BALLS+1 ; y := y+1)
  265.      if(check_for_match(balls[y]) = TRUE)
  266.         {
  267.         print(COL_GREEN,strpadleft(itostr(balls[y]),4,' '),COL_WHITE) ;
  268.         matches := matches + 1 ;
  269.         }
  270.      else
  271.         print(strpadleft(itostr(balls[y]),4,' ')) ;
  272.  
  273.   if(matches > 1)
  274.      winning_lines := winning_lines +1 ;
  275.  
  276.  
  277. // print out results if any matches
  278.   if(matches = 1)
  279.      {
  280.      print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_1," Minute",COL_WHITE ) ;
  281.      minutes_won := minutes_won+MATCHED_1 ;
  282.      }
  283.   else if(matches = 2)
  284.      {
  285.      print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_2," Minutes",COL_WHITE ) ;
  286.      minutes_won := minutes_won+MATCHED_2 ;
  287.      }
  288.   else if(matches = 3)
  289.          {
  290.          print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_3," Minutes",COL_WHITE ) ;
  291.          minutes_won := minutes_won+MATCHED_3 ;
  292.          }
  293.   else if(matches = 4)
  294.          {
  295.          print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_4," Minutes",COL_WHITE ) ;
  296.          minutes_won := minutes_won+MATCHED_4 ;
  297.          }
  298.   else if(matches = 5)
  299.          {
  300.          print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_5," Minutes",COL_WHITE ) ;
  301.          minutes_won := minutes_won+MATCHED_5 ;
  302.          }
  303.   else if(matches = 6)
  304.          {
  305.          print(AVATAR_GOTO,(char)(11+x),(char)40,COL_LCYAN,"You Won ",MATCHED_6," Minutes",COL_WHITE ) ;
  306.          minutes_won := minutes_won+MATCHED_6 ;
  307.          }
  308.        else
  309.          print(AVATAR_GOTO,(char)(11+x),(char)40,"You Have Not Won Anything!" ) ;
  310.  
  311. }
  312.  
  313. //simple check routine
  314. int check_for_match(int: ball_to_check)
  315. {
  316. int: x,swtch ;
  317.  
  318.  swtch := FALSE ;
  319.  
  320.  for(x := 1 ; x < BALLS+1 ; x := x+1)
  321.     if(user_balls[x] = ball_to_check)
  322.        swtch := TRUE ;
  323.  
  324. return swtch ;
  325. }
  326.  
  327. // show a very simple help screen
  328. void help()
  329. {
  330. // you should'nt need to touch this much,unless you choose differnt colours
  331. // for the results etc,but it does use the defines for most things.
  332. // and its only 1 screen long :)
  333.  
  334. char: x ;
  335.  
  336.   print(AVATAR_GOTO,(char)5,(char)1,"Do you need instructions [y/N]" ) ;
  337.   x := getch() ;
  338.   if(x = 'Y' or x = 'y') // check if intructions needed
  339.      {}
  340.   else
  341.      return ;              // if not then lets get back to business
  342.  
  343.   print(AVATAR_GOTO,(char)5,(char)1 ) ;
  344.   print("The object of this game is to gain on-line time,you do this by playing ",
  345.       "\nthe lottery,with a slight difference,you are gambling your time for    ",
  346.       "\ntoday,if you lose it all don't worry,you'll be back to normal tomorrow.",
  347.       "\n",
  348.       "\nYou pick ",BALLS," numbers within the range of 1 to ",RANDOM,
  349.       ",and then decide how many",
  350.       "\nlines you want the computer to generate,each line costs you ",BET," minutes,   ",
  351.       "\nand you can have a maximum of ",MAX_LINES," lines.                     ",
  352.       "\nYou can win time back for a match on 2 to ",BALLS," numbers,upto a maximum of   ",
  353.       "\n",MAX_TIME," minutes.",
  354.       "\nWhen you get a matching number it will show up as green eg ",COL_GREEN,"10"
  355.       ,COL_WHITE," and any    ",
  356.       "\ntime won will show up as blue eg ",COL_LCYAN,"15",COL_WHITE,".",
  357.       "\n",
  358.       "\nThats about it really,if you have problems please,let the sysop know,so   ",
  359.       "\nI can fix them quickly.",
  360.       "\n\nHave Fun. Mark Taylor.",
  361.       "\n\nPress A Key"
  362.       ) ;
  363.  
  364.   x := getch() ;
  365.   // Clear the screen from just below the title
  366.   for(x := 5 ; x < 23 ; x:= x+1)
  367.      print(AVATAR_GOTO,(char)x,(char)1,blanks ) ;
  368. }
  369.  
  370. // Print out stats
  371. void print_stats()
  372. {
  373. int: x ;
  374. long: mins_left ; // work out correct mins left,for some reason my orginal
  375.                   // way did'nt always come up with the right answer.
  376.                   // no idea why not though,if anyone has please let me know
  377.  
  378.   mins_left := (start_mins - (number_of_bets * BET)) + minutes_won ;
  379.  
  380.   print_title() ;
  381.   print(COL_YELLOW,"\n",centre("S T A T I S T I C S\n")) ;
  382.   print(centre("~~~~~~~~~~~~~~~~~~~~~\n"),COL_WHITE) ;
  383.  
  384.   if(minutes_won > MAX_TIME)
  385.      minutes_won := MAX_TIME ;
  386.  
  387.   print("\n                  Number of minutes at the start - ",
  388.         strpadleft(itostr(start_mins),4,' ')) ;
  389.  
  390.   print("\n                  Number of bets placed          - ",
  391.         strpadleft(itostr(number_of_bets),4,' ')) ;
  392.  
  393.   print("\n                  Total minutes bet              - ",COL_LRED,
  394.         strpadleft(itostr( (number_of_bets * BET) ),4,' '),COL_WHITE) ;
  395.  
  396.   print("\n                  Total of minutes won           - ",COL_LGREEN,
  397.         strpadleft(itostr(minutes_won),4,' '),COL_WHITE) ;
  398.  
  399. //  print("\n                  Number of minutes left         - ",
  400. //        strpadleft(itostr(timeleft()),4,' ')) ;
  401.  
  402.   print("\n                  Number of minutes left         - ",
  403.         strpadleft(itostr(mins_left),4,' ')) ;
  404.  
  405.   if(mins_left = start_mins)
  406.      print("\n\n                  You neither lost or won,but broke even!") ;
  407.   else if(mins_left > start_mins)
  408.      print("\n\n                  You ",COL_LGREEN,"gained",COL_WHITE,
  409.            " a total of ",COL_LGREEN,mins_left - start_mins,COL_WHITE," minutes.") ;
  410.   else
  411.      print("\n\n                  You ",COL_LRED,"lost",COL_WHITE,
  412.            " a total of ",COL_LRED,start_mins - mins_left,COL_WHITE," minutes.") ;
  413.  
  414.   print("\n\n\n                        Please Press A Key") ;
  415.   x := getch() ;
  416. }
  417.  
  418. // main loop
  419. int main()
  420. {
  421. // it does seem as though the user comes off worse most times :)
  422. // I expect this could be changed so there is a slight bias in favour of the user,
  423. // but that would take all the fun out of it :)
  424.  
  425. int: x ;
  426.  
  427.      time_check(FALSE) ;// STOP time checking
  428.      log("TStarting Lottery Time Gamble"); // Log the start to logfile
  429.      start_mins := timeleft() ; // get minutes left
  430.      srand(time()); // Seed random generator
  431.      blanks := strpad(blanks,term_width(),' ') ; // set a blank line to users screen width
  432.      minutes_won := 0 ;        // set winnings to zero
  433.      winning_lines := 0 ;      // set winning line to zero
  434.  
  435.      print_title() ;      // print title
  436.      help() ;             // check if instructions needed
  437.      get_user_numbers() ;  // Get user numbers
  438.      get_number_of_trys() ;   // get number of lines
  439.  
  440.      // go through each line bet
  441.      for(x:= 1 ; x < number_of_bets+1 ; x := x+1)
  442.         {
  443.         pick_numbers(computer_balls) ;
  444.         print_line(computer_balls,x) ;
  445.         }
  446.  
  447.   timeadjustsoft(minutes_won * 60 ) ; // Add any time won to user time,in minutes
  448.  
  449.   // Let user check lines and then go to stats screen
  450.   print("\n\n\n       Please Press A Key") ;
  451.   x := getch() ;
  452.   print_stats() ;   // print out bets minutes won etc
  453.   log("TWon "+itostr(minutes_won)+" minutes" ); // Log any winnings
  454.   time_check(TRUE) ; //Start time checking again!
  455.   cls() ; // clear screen and return to MAX
  456.  
  457. return 0 ;
  458. }
  459.  
  460.